package com.dbq.fast.business.product.event;

import android.os.Bundle;

import com.dbq.fast.App;
import com.facebook.appevents.AppEventsConstants;
import com.facebook.appevents.AppEventsLogger;

import java.math.BigDecimal;
import java.util.Currency;

/**
 */

public class FaceBookUserPurchaseTrack {
    private static AppEventsLogger logger = null;

    private static AppEventsLogger getFbAnalytics() {
        if (logger == null) {
            logger = AppEventsLogger.newLogger(App.getContext());
        }
        return logger;
    }

    public static void loginEvent() {
        getFbAnalytics().logEvent("LOGIN_SUCCESS");
    }


    public static void servicePage() {
        getFbAnalytics().logEvent("VIEW_ITEM_LIST");
    }

    public static void add2Cart(String serviceName, String serviceId) {
        Bundle parameters = new Bundle();
        parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, serviceName);
        parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, serviceId);
        getFbAnalytics().logEvent(AppEventsConstants.EVENT_NAME_ADDED_TO_CART, parameters);
    }

    public static void initCheckout(String contentType, String content) {
        Bundle events = new Bundle();
        events.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, contentType);
        events.putString(AppEventsConstants.EVENT_PARAM_CONTENT, content);
        events.putInt(AppEventsConstants.EVENT_PARAM_NUM_ITEMS, 1);
        events.putBoolean(AppEventsConstants.EVENT_PARAM_PAYMENT_INFO_AVAILABLE, true);
        events.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "CNY");
        getFbAnalytics().logEvent(AppEventsConstants.EVENT_NAME_INITIATED_CHECKOUT, events);
    }

    public static void logEvent(String eventName) {
        getFbAnalytics().logEvent(eventName);
    }

    public static void paySuccess(BigDecimal purchaseAmount, Currency currency) {
        getFbAnalytics().logPurchase(purchaseAmount, currency);
    }
}
